// pages/common/bill.js
Page({

    data: {
        page: 1,
        total: 2,
        loading: false,
        list: []
    },
    onLoad: function(options) {
        wx.showLoading({
            title: '加载中...',
        })
        this.loadData()
    },
    loadData() {
        let {
            page = 1, total = 2, loading = false, list = []
        } = this.data
        if (total <= list.length || loading) return
        this.setData({
            loading: true
        })
        getApp().http.post('rest/bill/queryByList.do', {
            data: {
                page,
                rows: 10
            }
        }).then(res => {
            page++
            total = res.obj.total
            loading = false
            list.push(...res.obj.rows)

            this.setData({
                page,
                total,
                loading,
                list
            })
            wx.hideLoading()
            wx.stopPullDownRefresh()
        }).catch(err => {
            this.setData({
                loading: false
            })
            getApp().wxToast.error(err.msg)
        })
    },
    toDetail(evt) {
        let id = evt.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/car-owner/personal/order-success?id=' + id,
        })
    },
    onPullDownRefresh() {
        this.setData({
            page: 1,
            total: 2,
            loading: false,
            list: []
        })
        this.loadData()
    },
    onReachBottom() {
        this.loadData()
    }
})